package com.example.rbacmanage.service.system.impl;

import com.example.rbacmanage.entity.system.Notice;
import com.example.rbacmanage.mapper.system.NoticeMapper;
import com.example.rbacmanage.service.system.NoticeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;
    @Override
    public void save(Notice notice) {
        notice.setCreateTime(new Date());
        noticeMapper.insert(notice);
    }

    @Override
    public void remove(Long[] ids) {
        for (Long id : ids) {
            noticeMapper.del(id);
        }
    }

    @Override
    public void update(Notice notice) {
        noticeMapper.update(notice);
    }

    @Override
    public List<Notice> getAll(Notice notice) {
        return noticeMapper.list(notice);
    }

    @Override
    public PageInfo<Notice> getPage(Notice notice) {
        PageHelper.startPage(notice.getPage(),notice.getLimit());
        return new PageInfo<>(getAll(notice));
    }

    @Override
    public Notice getById(Long id) {
        return noticeMapper.queryOneById(id);
    }

    @Override
    public Integer getCount(Notice notice) {
        return noticeMapper.count(notice);
    }
}
